Skip to content

fix(core): Don't let a throwing beforeSendSpan callback escape into user code - #22836

Draft
Lms24 wants to merge 1 commit into
feat/span-streaming-tree-shakingfrom
fix/before-send-span-throw
Draft

fix(core): Don't let a throwing beforeSendSpan callback escape into user code#22836
Lms24 wants to merge 1 commit into
feat/span-streaming-tree-shakingfrom
fix/before-send-span-throw

Conversation

@Lms24

@Lms24 Lms24 commented Jul 29, 2026

Copy link
Copy Markdown
Member

Wraps the beforeSendSpan callback application in captureSpan in a try/catch, logging the error and sending the span unmodified instead of letting the throw escape.

Spans are captured synchronously from the afterSpanEnd hook, so a throwing callback propagates straight out of whatever user code called span.end(). That turns a faulty Sentry option into an exception in unrelated application code — a failure mode the SDK should never introduce.

This is particularly relevant now that beforeSendSpan receives StreamedSpanJSON by default: a v10 callback that wasn't migrated and reaches into span.data throws on the first ended span, which would otherwise break the instrumented app rather than just degrading span processing. Falling back to the unmodified span keeps data flowing and surfaces the problem through a debug-build error log.

@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 30.01 kB +0.34% +100 B 🔺
@sentry/browser - with treeshaking flags 28.15 kB +0.15% +40 B 🔺
@sentry/browser (incl. Tracing) 47.45 kB +0.2% +94 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 47.48 kB +0.26% +121 B 🔺
@sentry/browser (incl. Tracing, Profiling) 52.23 kB +0.21% +105 B 🔺
@sentry/browser (incl. Tracing, Replay) 86.79 kB +0.12% +98 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 76.17 kB +0.06% +39 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 91.52 kB +0.12% +106 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 104.18 kB +0.14% +137 B 🔺
@sentry/browser (incl. Feedback) 47.31 kB +0.21% +96 B 🔺
@sentry/browser (incl. sendFeedback) 34.84 kB +0.26% +87 B 🔺
@sentry/browser (incl. FeedbackAsync) 39.95 kB +0.24% +92 B 🔺
@sentry/browser (incl. Metrics) 31.09 kB +0.32% +98 B 🔺
@sentry/browser (incl. Logs) 31.32 kB +0.32% +98 B 🔺
@sentry/browser (incl. Metrics & Logs) 31.99 kB +0.3% +93 B 🔺
@sentry/react 31.82 kB +0.28% +87 B 🔺
@sentry/react (incl. Tracing) 49.7 kB +0.2% +95 B 🔺
@sentry/vue 35.1 kB +0.36% +124 B 🔺
@sentry/vue (incl. Tracing) 49.45 kB +0.23% +112 B 🔺
@sentry/svelte 30.04 kB +0.36% +105 B 🔺
CDN Bundle 32.02 kB +0.07% +22 B 🔺
CDN Bundle (incl. Tracing) 47.72 kB +0.02% +7 B 🔺
CDN Bundle (incl. Logs, Metrics) 33.57 kB +0.06% +19 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 49.09 kB +0.03% +11 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 72.91 kB +0.03% +19 B 🔺
CDN Bundle (incl. Tracing, Replay) 85.35 kB +0.01% +6 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.65 kB +0.01% +2 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 91.15 kB +0.02% +11 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.45 kB +0.01% +6 B 🔺
CDN Bundle - uncompressed 95.47 kB -0.03% -22 B 🔽
CDN Bundle (incl. Tracing) - uncompressed 143.06 kB -0.02% -23 B 🔽
CDN Bundle (incl. Logs, Metrics) - uncompressed 100.19 kB -0.03% -22 B 🔽
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 147.04 kB -0.02% -23 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 224.94 kB -0.01% -22 B 🔽
CDN Bundle (incl. Tracing, Replay) - uncompressed 262.31 kB -0.01% -23 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 266.28 kB -0.01% -23 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 276.02 kB -0.01% -23 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 279.97 kB -0.01% -23 B 🔽
@sentry/nextjs (client) 52.28 kB +0.14% +73 B 🔺
@sentry/sveltekit (client) 47.91 kB +0.24% +114 B 🔺
@sentry/core/server 80.13 kB +0.16% +126 B 🔺
@sentry/core/browser 52.07 kB +0.21% +108 B 🔺
@sentry/node 121 kB +0.1% +113 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 0 B added added
@sentry/node - without tracing 83.61 kB -0.78% -652 B 🔽
@sentry/aws-serverless 93.03 kB +0.12% +107 B 🔺
@sentry/cloudflare (withSentry) - minified 219.46 kB +0.06% +118 B 🔺
@sentry/cloudflare (withSentry) 540.59 kB +0.03% +157 B 🔺

View base workflow run

@Lms24
Lms24 force-pushed the fix/before-send-span-throw branch from 2b3d3e2 to 192e001 Compare July 29, 2026 15:37
… user code

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Lms24
Lms24 force-pushed the fix/before-send-span-throw branch from 192e001 to f1557e3 Compare August 3, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant